//
//  SetViewController.m
//  MyNewBase
//
//  Created by 胡超 on 16/3/9.
//  Copyright © 2016年 lbanma. All rights reserved.
//

#import "SetViewController.h"
#import "AccountViewController.h"

@interface SetViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic,strong) UITableView *tableView;

@end

@implementation SetViewController


-(instancetype)init{
    if (self = [super init]) {
        self.title = @"个人";
        self.tabBarItem.image = [UIImage imageNamed:@"tabbar_item_more"];
        self.tabBarItem.selectedImage = [UIImage imageNamed:@"tabbar_item_more_selected"];
    }
    return self;
}

-(UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [self.view addSubview:_tableView];
        [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_equalTo(0);
        }];
        [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    }
    return _tableView;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 1;
    }else if (section == 1){
        return 2;
    }else{
        return 3;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    if (indexPath.section == 0) {
        
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
        cell.imageView.image = [UIImage imageNamed:@"tabbar_selected_back"];
        cell.textLabel.text = @"夜宵";
        cell.detailTextLabel.text = @"1885527XXXX";
    }else if (indexPath.section == 1){
        if (indexPath.row == 0) {
            cell.imageView.image = [UIImage imageNamed:@"tabbar_selected_back"];
            cell.textLabel.text = @"我的收藏";
        }else{
            cell.imageView.image = [UIImage imageNamed:@"tabbar_selected_back"];
            cell.textLabel.text = @"推荐有奖";
        }
    }else {
        if (indexPath.row == 0) {
            cell.imageView.image = [UIImage imageNamed:@"tabbar_selected_back"];
            cell.textLabel.text = @"我的红包";
        }else if(indexPath.row == 1){
            cell.imageView.image = [UIImage imageNamed:@"tabbar_selected_back"];
            cell.textLabel.text = @"服务中心";
        }else{
            cell.imageView.image = [UIImage imageNamed:@"tabbar_selected_back"];
            cell.textLabel.text = @"我是商家";
        }

    }
    
    return cell;
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 0) {
        cell.backgroundColor = [UIColor grayColor];
        
        cell.textLabel.backgroundColor = [UIColor clearColor];
        cell.detailTextLabel.backgroundColor = [UIColor clearColor];
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        return 80;
    }else{
        return 60;
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (indexPath.section == 0) {
        AccountViewController *accountVC = [[AccountViewController alloc]init];
        [self.navigationController pushViewController:accountVC animated:YES];
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 10;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.tableView.hidden = NO;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
